package com.bwie.product.controller;

import com.bwie.common.core.domain.PageResult;
import com.bwie.common.core.domain.Result;
import com.bwie.product.domain.dto.SpuInfoDTO;
import com.bwie.product.domain.vo.SpuInfoVO;
import com.bwie.product.service.SpuInfoMerchantService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/spuInfo")
@RestController
@Log4j2
public class SpuInfoMerchantController {
    @Autowired
    private SpuInfoMerchantService spuInfoMerchantService;

    @Autowired
    private HttpServletRequest request;

    /**
     * 商户端
     * 获取spu列表
     */
    @PostMapping("/getSpuInfoList")
    public Result<PageResult<SpuInfoVO>> getSpuInfoList(@RequestBody SpuInfoDTO spuInfoDTO){
        log.info("功能名称：商户端获取spu列表，请求url：{}，请求方式：{}，请求参数：{}",request.getRequestURI(),request.getMethod(),spuInfoDTO);
        PageResult<SpuInfoVO> spuInfoVOPageResult = spuInfoMerchantService.getSpuInfoList(spuInfoDTO);
        Result<PageResult<SpuInfoVO>> result = Result.success(spuInfoVOPageResult);
        log.info("功能名称：商户端获取spu列表，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 商家端
     * 商品上下架
     * @return
     */
    @PutMapping("/upperOrLowerShelves/{id}/{publishStatus}")
    public Result upperOrLowerShelves(@PathVariable Long id,@PathVariable Integer publishStatus){
        log.info("功能名称：商户端商品上下架，请求url：{}，请求方式：{}，请求参数：{}、{}",request.getRequestURI(),request.getMethod(),id,publishStatus);
        spuInfoMerchantService.upperOrLowerShelves(id,publishStatus);
        Result<Object> result = Result.success();
        log.info("功能名称：商户端商品上下架，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }
}
